import java.util.Arrays;
import java.util.Comparator;

class Solution {
    public int findLongestChain(int[][] pairs) {
        int n = pairs.length ;
        int m = pairs[0].length ;
        Arrays.sort(pairs , new Comparator<int[]>(){
          public int compare(int[]a , int[]b){
            return a[0]-b[0];
          }
        });
        int sum = 0 ; 
        int[] dp = new int[n] ; 
        for(int i=0; i < n ; i ++){
            dp[i] = 1 ;
            for(int j= i-1 ; j >= 0 ; j --){
               if(pairs[i][0] > pairs[j][m-1]){
                 dp[i] = Math.max(dp[i] , dp[j]+1) ; 
               }
            }
            sum = Math.max(dp[i] , sum) ;
        } 

      return sum ;
    }
}